home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1992 / number1 / sketch / osketch.cpp next >
C/C++ Source or Header  |  1992-02-06  |  2KB  |  97 lines

  1. //  OSKETCH.CPP by Tom Swan
  2.  
  3. #include <owl.h>
  4. #include "osketch.h"
  5.  
  6. class TSketchApp: public TApplication
  7. {
  8. public:
  9.   TSketchApp(LPSTR aName, HANDLE hInstance, HANDLE hPrevInstance,
  10.     LPSTR lpCmd, int nCmdShow) : TApplication(aName, hInstance,
  11.     hPrevInstance, lpCmd, nCmdShow) {};
  12.   virtual void InitMainWindow();
  13. };
  14.  
  15. _CLASSDEF(TSketchWin)
  16. class TSketchWin: public TWindow
  17. {
  18. public:
  19.   HDC dc;          // Handle to display context
  20.   BOOL dragging;   // True if clicking and dragging mouse
  21.   TSketchWin(PTWindowsObject AParent, LPSTR ATitle);
  22.   virtual void IDMErase(RTMessage)
  23.     = [CM_FIRST + IDM_ERASE];
  24.   virtual void IDMExit(RTMessage)
  25.     = [CM_FIRST + IDM_EXIT];
  26.   virtual void WMLButtonDown(RTMessage Msg)
  27.     = [WM_FIRST + WM_LBUTTONDOWN];
  28.   virtual void WMMouseMove(RTMessage Msg)
  29.     = [WM_FIRST + WM_MOUSEMOVE];
  30.   virtual void WMLButtonUp(RTMessage)
  31.     = [WM_FIRST + WM_LBUTTONUP];
  32. };
  33.  
  34.  
  35. // Initialize TSketchApp's main window
  36. void TSketchApp::InitMainWindow()
  37. {
  38.   MainWindow = new TSketchWin(NULL, "ObjectWindows Sketch");
  39. }
  40.  
  41. // Initialize the application's main window
  42. TSketchWin::TSketchWin(PTWindowsObject AParent, LPSTR ATitle)
  43.   : TWindow(AParent, ATitle)
  44. {
  45.   AssignMenu(IDM_MENU);
  46.   dragging = FALSE;
  47. }
  48.  
  49. // Erase window
  50. void TSketchWin::IDMErase(RTMessage)
  51. {
  52.   InvalidateRect(HWindow, NULL, TRUE);
  53. }
  54.  
  55. // Exit program
  56. void TSketchWin::IDMExit(RTMessage)
  57. {
  58.   CloseWindow();
  59. }
  60.  
  61. // Respond to left-mouse-button click
  62. void TSketchWin::WMLButtonDown(RTMessage Msg)
  63. {
  64.   if (!dragging) {
  65.     dragging = TRUE;
  66.     SetCapture(HWindow);
  67.     dc = GetDC(HWindow);
  68.     MoveTo(dc, Msg.LP.Lo, Msg.LP.Hi);
  69.   }
  70. }
  71.  
  72. // Respond to mouse movement
  73. void TSketchWin::WMMouseMove(RTMessage Msg)
  74. {
  75.   if (dragging)
  76.     LineTo(dc, Msg.LP.Lo, Msg.LP.Hi);
  77. }
  78.  
  79. // Respond to release of left mouse button
  80. void TSketchWin::WMLButtonUp(RTMessage)
  81. {
  82.   if (dragging) {
  83.     ReleaseCapture();
  84.     ReleaseDC(HWindow, dc);
  85.     dragging = FALSE;
  86.   }
  87. }
  88.  
  89. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  90.   LPSTR lpCmd, int nCmdShow)
  91. {
  92.   TSketchApp SketchApp("osketch", hInstance, hPrevInstance,
  93.     lpCmd, nCmdShow);
  94.   SketchApp.Run();
  95.   return SketchApp.Status;
  96. }
  97.